<?xml version='1.0' encoding='UTF-8'?>

<ui:composition template="templates/template.xhtml" xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:a4j="http://richfaces.org/a4j"
	xmlns:rich="http://richfaces.org/rich"
	xmlns:c="http://java.sun.com/jstl/core">

	<ui:define name="content">

	<h:form id="page" prependId="false">

		<rich:dataTable id="veiculoList" rowClasses="even,odd" value="#{mobileBean.entities}" var="veiculo">

			<rich:column>
				<b><h:outputText value="#{veiculo.nome}"/></b><br/>

				<h:outputText value="#{veiculo.dataTransmissao}">
					<f:convertDateTime pattern="HH:mm:ss dd/MM/yy" timeZone="GMT-03:00"/>
				</h:outputText>
				<br/>

				<h:outputText value="Lat: "/>
				<h:outputText value="#{veiculo.geometry.x}">
					<f:convertNumber maxFractionDigits="6" minFractionDigits="6" maxIntegerDigits="2"/>
				</h:outputText>
				<br/>

				<h:outputText value="Lng: "/>
				<h:outputText value="#{veiculo.geometry.y}">
					<f:convertNumber maxFractionDigits="6" minFractionDigits="6" maxIntegerDigits="2"/>
				</h:outputText>
				<br/>

				<h:outputText value="A "/>
				<h:outputText value="#{veiculo.distancia}">
					<f:convertNumber maxFractionDigits="2" maxIntegerDigits="2"/>
				</h:outputText>
				<h:outputText value="m do ponto "/>
				<h:outputText value="#{veiculo.ponto.nome}"/>
				<br/>

				<h:outputText value="Velocidade: "/>
				<h:outputText value="Parado" rendered="#{veiculo.velocidade == 0}"/>
				<h:outputText value="#{veiculo.velocidade}" rendered="#{veiculo.velocidade != 0}">
					<f:convertNumber maxFractionDigits="2" maxIntegerDigits="2"/>
				</h:outputText>
				<h:outputText value="Km/h" rendered="#{veiculo.velocidade != 0}"/>
				<br/>

				<h:outputText value="Ignicao: "/>
				<h:outputText value="Ligada" rendered="#{veiculo.statusIgnicao}"/>
				<h:outputText value="Desligada" rendered="#{!veiculo.statusIgnicao}"/>
				<br/>

				<h:outputText value="PANICO ACIONADO" rendered="#{veiculo.statusPanico}"/>
				<br/>

				<a4j:commandLink action="#{mobileBean.prepareLigarSirene}" value="LIGAR SIRENE" reRender="veiculoList">
					<f:setPropertyActionListener target="#{mobileBean.entity.id}" value="#{veiculo.id}"/>
					<f:setPropertyActionListener target="#{mobileBean.comandoId}" value="#{1}"/>
					<a4j:support event="onclick"  reRender="successMessage,failMessage"/>
				</a4j:commandLink>

				<br/>

				<a4j:commandLink action="#{mobileBean.prepareDesligarSirene}" value="DESLIGAR SIRENE" reRender="veiculoList,successMessage,failMessage">
					<f:setPropertyActionListener target="#{mobileBean.entity.id}" value="#{veiculo.id}"/>
					<f:setPropertyActionListener target="#{mobileBean.comandoId}" value="#{2}"/>
				</a4j:commandLink>

				<br/>

				<a4j:commandLink action="#{mobileBean.prepareBloquear}" value="BLOQUEAR" reRender="veiculoList,successMessage,failMessage">
					<f:setPropertyActionListener target="#{mobileBean.entity.id}" value="#{veiculo.id}"/>
					<f:setPropertyActionListener target="#{mobileBean.comandoId}" value="#{3}"/>
				</a4j:commandLink>

				<br/>

				<a4j:commandLink action="#{mobileBean.prepareDesbloquear}" value="DESBLOQUEAR" reRender="veiculoList,successMessage,failMessage">
					<f:setPropertyActionListener target="#{mobileBean.entity.id}" value="#{veiculo.id}"/>
					<f:setPropertyActionListener target="#{mobileBean.comandoId}" value="#{4}"/>
				</a4j:commandLink>

				<br/>

				<a4j:commandLink action="#{mobileBean.prepareBloquearLigarSirene}" value="BLOQUEAR E LIGAR SIRENE" reRender="veiculoList,successMessage,failMessage">
					<f:setPropertyActionListener target="#{mobileBean.entity.id}" value="#{veiculo.id}"/>
					<f:setPropertyActionListener target="#{mobileBean.comandoId}" value="#{5}"/>
				</a4j:commandLink>

				<br/><br/>

				<h:outputText id="successMessage" value="#{mobileBean.message}" rendered="#{mobileBean.statusMessageSuccess == true  and veiculo.id == mobileBean.entity.id}" style="color:green"/>
				<h:outputText id="failMessage" value="#{mobileBean.message}" rendered="#{mobileBean.statusMessageFail == true  and veiculo.id == mobileBean.entity.id}" style="color:red"/>

				<h:outputLabel value=" Senha:"  rendered="#{mobileBean.statusSenhaBloqueio and veiculo.id == mobileBean.entity.id}"/>
				<h:inputSecret value="#{mobileBean.senhaBloqueio}"  rendered="#{mobileBean.statusSenhaBloqueio and veiculo.id == mobileBean.entity.id}" maxlength="12" size="10"/>

				<h:commandButton action="#{mobileBean.ligarSirene}" value="OK" styleClass="button" rendered="#{mobileBean.statusSenhaBloqueio  and veiculo.id == mobileBean.entity.id and mobileBean.comandoId == 1}">
					<f:setPropertyActionListener target="#{mobileBean.entity.id}" value="#{veiculo.id}"/>
					<a4j:support event="oncomplete" action="#{mobileBean.populate}" reRender="veiculoList,successMessage,failMessage"/>				
				</h:commandButton>

				<h:commandButton action="#{mobileBean.desligarSirene}" value="OK" styleClass="button" rendered="#{mobileBean.statusSenhaBloqueio  and veiculo.id == mobileBean.entity.id and mobileBean.comandoId == 2}">
					<f:setPropertyActionListener target="#{mobileBean.entity.id}" value="#{veiculo.id}"/>
					<a4j:support event="oncomplete" action="#{mobileBean.populate}" reRender="veiculoList,successMessage,failMessage"/>				
				</h:commandButton>

				<h:commandButton action="#{mobileBean.bloquear}" value="OK" styleClass="button" rendered="#{mobileBean.statusSenhaBloqueio  and veiculo.id == mobileBean.entity.id and mobileBean.comandoId == 3}">
					<f:setPropertyActionListener target="#{mobileBean.entity.id}" value="#{veiculo.id}"/>
					<a4j:support event="oncomplete" action="#{mobileBean.populate}" reRender="veiculoList,successMessage,failMessage"/>				
				</h:commandButton>

				<h:commandButton action="#{mobileBean.desbloquear}" value="OK" styleClass="button" rendered="#{mobileBean.statusSenhaBloqueio  and veiculo.id == mobileBean.entity.id and mobileBean.comandoId == 4}">
					<f:setPropertyActionListener target="#{mobileBean.entity.id}" value="#{veiculo.id}"/>
					<a4j:support event="oncomplete" action="#{mobileBean.populate}" reRender="veiculoList,successMessage,failMessage"/>				
				</h:commandButton>

				<h:commandButton action="#{mobileBean.bloquearLigarSirene}" value="OK" styleClass="button" rendered="#{mobileBean.statusSenhaBloqueio  and veiculo.id == mobileBean.entity.id and mobileBean.comandoId == 5}">
					<f:setPropertyActionListener target="#{mobileBean.entity.id}" value="#{veiculo.id}"/>
					<a4j:support event="oncomplete" action="#{mobileBean.populate}" reRender="veiculoList,successMessage,failMessage"/>				
				</h:commandButton>

				<h:commandButton action="#{mobileBean.cancelar}" value="X" styleClass="button" rendered="#{mobileBean.statusSenhaBloqueio  and veiculo.id == mobileBean.entity.id}">
					<f:setPropertyActionListener target="#{mobileBean.entity.id}" value="#{veiculo.id}"/>
					<a4j:support event="oncomplete" action="#{mobileBean.populate}" reRender="veiculoList,successMessage,failMessage"/>				
				</h:commandButton>

			</rich:column>

		</rich:dataTable>

		<br/>

		<a4j:commandLink id="userLogout" action="#{controlBean.logout}" value="Logout" reRender="page"/>

		</h:form>

	</ui:define>

</ui:composition>